<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var date = new Date();
        // 获取当前时间
        console.log(date);
        var Year = date.getFullYear();
        var Month = date.getMonth() + 1;
        var Dates = date.getDate();
        var arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
        var Day = date.getDay();
        console.log('今天是' + Year + '年' + Month + '月' + Dates + '日' + arr[Day]);
    </script>
</head>

<body>

    <button>获取当前系统时间</button>
    <div>此处显示时间</div>


    <script>
        // 1.获取元素
        var btn = document.querySelector('button');
        var div = document.querySelector('div');
        // 2.绑定事件
        btn.onclick = function() {
            var date = new Date();
            var Year = date.getFullYear();
            var Month = date.getMonth() + 1;
            var Dates = date.getDate();
            var arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
            var Day = date.getDay();
            var hour = date.getHours();
            var minute = date.getMinutes();
            div.innerText = Year + '年' + Month + '月' + Dates + '日' + arr[Day] + ' ' + hour + '时' + minute + '分';

        }
    </script>

</body>

</html>